package dao.Seller.impl;

import dao.BaseDao;
import dao.Seller.SmallclassDao;
import pojo.Discount;
import pojo.Seller;
import pojo.Smallclass;

import java.sql.ResultSet;
import java.sql.Timestamp;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * 添加下拉列表内容
 */
public class SmallclassDaoImpl extends BaseDao implements SmallclassDao {

    /**
     * 添加小分类
     * @return
     */
    @Override
    public List<Smallclass> addSmallclass() {
        List<Smallclass> ListSmallclass = new ArrayList<>();
        try {
            Smallclass smallclass = null;
            String sql = "SELECT * FROM smallclass";
            Object[] params = {};
            ResultSet rs = this.executeSelect(sql, params);
            while (rs.next()) {
                smallclass = new Smallclass();
                long smallId = rs.getLong("id");
                String smallName = rs.getString("smallName");  //小分类名称
                long smallBigId = rs.getLong("smallBigId");   //小分类对应的大分类ID
                String smallText = rs.getString("smallText");
                smallclass.setSmallId(smallId);
                smallclass.setSmallName(smallName);
                smallclass.setSmallBigId(smallBigId);
                smallclass.setSmallText(smallText);
                ListSmallclass.add(smallclass);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return ListSmallclass;
    }

    /**
     * 添加商家名称
     * @return
     */
    @Override
    public List<Seller> addSeller() {
        List<Seller> ListSeller =new ArrayList<>();
        try {
            Seller seller =null;
            String sql = "SELECT * FROM seller";
            Object[] params = {};
            ResultSet rs = this.executeSelect(sql, params);
            while (rs.next()) {
                seller = new Seller();
                 long id=rs.getLong("id");             //商家id
                 String sellerName=rs.getString("sellerName");   //商家真实名称
                 String sellerUser=rs.getString("sellerUser");   //商家昵称
                 String sellerSex=rs.getString("sellerSex");       //商家性别
                 Timestamp sellerBirthday = rs.getTimestamp("sellerBirthday");//商家生日
                 String sellerIdCard=rs.getString("sellerIdCard");    //商家身份证
                 String sellerEmail=rs.getString("sellerEmail");      //邮箱
                 String sellerTel=rs.getString("sellerTel");        //电话
                 String sellerAddress=rs.getString("sellerAddress");    //地址
                 seller.setId(id);
                 seller.setSellerName(sellerName);
                 seller.setSellerUser(sellerUser);
                 seller.setSellerSex(sellerSex);
                 seller.setSellerBirthday(sellerBirthday);
                 seller.setSellerIdCard(sellerIdCard);
                 seller.setSellerEmail(sellerEmail);
                 seller.setSellerTel(sellerTel);
                 seller.setSellerAddress(sellerAddress);
                 ListSeller.add(seller);
            }
        } catch (Exception ex) {
            ex.printStackTrace();
        }
        return ListSeller;
    }

    /**
     * 添加折扣率
     * @return
     */
    @Override
    public List<Discount> addDiscount() {
        List<Discount> ListDiscount =new ArrayList<>();
        try{
            Discount discount =null;
            String sql="select * from discount";
            Object[] params={};
            ResultSet rs=this.executeSelect(sql,params);
            while (rs.next()){
                discount=new Discount();
                long id =rs.getLong("id");        //折扣id
                double discRate=rs.getDouble("discRate");   //折扣率
                discount.setId(id);
                discount.setDiscRate(discRate);
                ListDiscount.add(discount);
            }
        }catch (Exception ex){
            ex.printStackTrace();
        }
        return ListDiscount;
    }
}